package spring.cloud.tasks.executor.task;


import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * 执行状态节点名称的常量类.
 */
@Slf4j
@Setter
@Getter
public final class ExecuteNode {
    /**
     * 执行状态根节点.
     */
    public static final String ROOT = "execute";
    /**
     * 作业执行execution节点
     */
    public static final String EXECUTE_NODE = ROOT + "/%s";
    /**
     * 作业运行
     */
    public static final String EXECUTE_NODE_RUNNING = ROOT + "/%s/running";
    //
    public static final String EXECUTE_NODE_LAST_BEGIN_TIME = ROOT + "/%s/lastBeginTime";
    //
    public static final String EXECUTE_NODE_NEXT_FIRE_TIME = ROOT + "/%s/nextFireTime";
    /**
     * 作业完成
     */
    public static final String EXECUTE_NODE_COMPLETED = ROOT + "/%s/completed";
    //
    public static final String EXECUTE_NODE_LAST_COMPLETE_TIME = ROOT + "/%s/lastCompleteTime";
    /**
     * 执行失败
     */
    public static final String EXECUTE_NODE_FAILED = ROOT + "/%s/failed";
    /**
     * 执行超时
     */
    public static final String EXECUTE_NODE_TIMEOUT = ROOT + "/%s/timeout";
    /**
     * 作业执行返回信息
     */
    public static final String EXECUTE_NODE_MESSAGE = ROOT + "/%s/message";
    /**
     * 作业日志信息
     */
    public static final String EXECUTE_NODE_LOG = ROOT + "/%s/log";
    private final String taskId;

    public ExecuteNode(final String taskId) {
        this.taskId = taskId;
    }

    public static String getExecuteNode(final String taskItemIndex) {
        return String.format(EXECUTE_NODE, taskItemIndex);
    }

    public static String getLastBeginTimeNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_LAST_BEGIN_TIME, taskItemIndex);
    }
    //

    /**
     * 获取作业运行状态节点路径.
     *
     * @param taskItemIndex 作业项
     * @return 作业运行状态节点路径
     */
    public static String getRunningNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_RUNNING, taskItemIndex);
    }

    public static String getNextFireTimeNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_NEXT_FIRE_TIME, taskItemIndex);
    }
    //

    public static String getCompletedNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_COMPLETED, taskItemIndex);
    }

    public static String getLastCompleteTimeNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_LAST_COMPLETE_TIME, taskItemIndex);
    }
    //

    /**
     * 执行出错节点
     */
    public static String getFailedNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_FAILED, taskItemIndex);
    }

    /**
     * 执行超时节点
     */
    public static String getTimeoutNode(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_TIMEOUT, taskItemIndex);
    }
    //

    /**
     * 作业执行返回信息
     */
    public static String getMessage(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_MESSAGE, taskItemIndex);
    }

    /**
     * 作业运行日志
     */
    public static String getLog(final int taskItemIndex) {
        return String.format(EXECUTE_NODE_LOG, taskItemIndex);
    }
}
